/**
 * Aether Colors v2
 * by Xavier Gouchet (2008)
 **/

 	
// movie save

// Canvas Size
int width = 512;
int height = 512;

// Frames
float time = 0;
float limit = 256;

// Static variables
float pi = 3.14159265;
float d2r = (2*pi)/360.0;

// Font
PFont fontA = createFont("Courier", 12);

// Coloring Mode 
int sat = (round(random(100))%2)*256;
int val = 256;
int bg = (round(random(100))%2)*255;
int fg = 255 - bg;

// Speeds
int l1 = round(random(100));
int l2 = round(random(100));
int l3 = round(random(100));
int l4 = round(random(100));
int l5 = round(random(100));
int l6 = round(random(100));
int l7 = round(random(100));
int l8 = round(random(100));
// Size
int s1 = round(max(width/32,width/3));
int s2 = round(max(height/32,height/3));
int s3 = round(max(width/32,width/3));
int s4 = round(max(height/32,height/3));
int s5 = round(max(width/32,width/3));
int s6 = round(max(height/32,height/3));
int s7 = round(max(width/32,width/3));
int s8 = round(max(height/32,height/3));
// Position
int p1 = round(random(s1, width-s1));
int p2 = round(random(s2, height-s2));
int p3 = round(random(s3, width-s3));
int p4 = round(random(s4, height-s4));
int p5 = round(random(s5, width-s5));
int p6 = round(random(s6, height-s6));
int p7 = round(random(s7, width-s7));
int p8 = round(random(s8, height-s8));

void setup(){
  size(width,height);
  frameRate(60);
  smooth();
  if (sat==0) {
    val = fg; 
  }
    background(bg);
}


void draw(){
  if (time<limit){
    for (int i=0; i<4; i++){
      //increment time
      time+= 0.05;

      // Create parametric position
      float Ax = (sin(time*d2r*l1*0.1) * s1) + p1;
      float Ay = (sin(time*d2r*l2*0.1) * s2) + p2;
      float Bx = (sin(time*d2r*l3*0.1) * s3) + p3;
      float By = (cos(time*d2r*l4*0.1) * s4) + p4;
      float Cx = (sin(time*d2r*l5*0.1) * s5) + p5;
      float Cy = (sin(time*d2r*l6*0.1) * s6) + p6;
      float Dx = (sin(time*d2r*l7*0.1) * s7) + p7;
      float Dy = (cos(time*d2r*l8*0.1) * s8) + p8;


      // Set color mode
      colorMode(HSB, 256);
      //background(bg);
      stroke( (round(time)%255),sat,val,3);
      noFill();

      // draw line
      bezier(Ax,Ay,Bx,By,Cx,Cy,Dx,Dy);
    }
  } 
  else {
    if (time<=limit+1){
      // write params 
      textFont(fontA,12);
      fill(fg);
      String s;

      // Speed params
      s = "Speeds    : " + str(l1) + " ; " + str(l2) + " ; " + str(l3) + " ; " + str(l4) + " ; " + str(l5) + " ; " + str(l6) + " ; " + str(l7) + " ; " + str(l8);
      text(s,10,15);

      // Size params
      s = "Sizes     : " + str(s1) + " ; " + str(s2) + " ; " + str(s3) + " ; " + str(s4) + " ; " + str(s5) + " ; " + str(s6) + " ; " + str(s7) + " ; " + str(s8);
      text(s,10,25);

      // Position params
      s = "Positions : " + str(p1) + " ; " + str(p2) + " ; " + str(p3) + " ; " + str(p4) + " ; " + str(p5) + " ; " + str(p6) + " ; " + str(p7) + " ; " + str(p8);
      text(s,10,35);
      time = limit +2;

      // Stop the programm
      exit();
    }
  }
}